home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / BBS-Archive / Comm / AmiTCP30b2.lha / src / amitcp / kern / uipc_domain.c < prev    next >
C/C++ Source or Header  |  1993-08-12  |  7KB  |  262 lines

  1. RCS_ID_C="$Id: uipc_domain.c,v 1.11 1993/06/04 11:16:15 jraja Exp $";
  2. /*
  3.  * Copyright (c) 1993 AmiTCP/IP Group, <amitcp-group@hut.fi>
  4.  *                    Helsinki University of Technology, Finland.
  5.  *                    All rights reserved.
  6.  *
  7.  * HISTORY
  8.  * $Log: uipc_domain.c,v $
  9.  * Revision 1.11  1993/06/04  11:16:15  jraja
  10.  * Fixes for first public release.
  11.  *
  12.  * Revision 1.10  1993/05/17  01:07:47  ppessi
  13.  * Changed RCS version.
  14.  *
  15.  * Revision 1.9  1993/04/06  15:16:00  jraja
  16.  * Changed spl function return value storage to spl_t,
  17.  * changed bcopys and bzeros to aligned and/or const when possible,
  18.  * added inclusion of conf.h to every .c file.
  19.  *
  20.  * Revision 1.8  93/03/13  17:13:03  17:13:03  ppessi (Pekka Pessi)
  21.  * Fixed bugs with variable initializations. Works with UDP.
  22.  * 
  23.  * Revision 1.7  93/03/05  03:26:19  03:26:19  ppessi (Pekka Pessi)
  24.  * Compiles with SASC. Initial test version.
  25.  * 
  26.  * Revision 1.6  93/03/04  09:57:53  09:57:53  jraja (Jarno Tapio Rajahalme)
  27.  * Fixed includes.
  28.  * 
  29.  * Revision 1.5  93/03/03  19:56:06  19:56:06  jraja (Jarno Tapio Rajahalme)
  30.  * Moved 'domains' definition here from sys/domain.h.
  31.  * 
  32.  * Revision 1.4  93/02/24  12:55:09  12:55:09  jraja (Jarno Tapio Rajahalme)
  33.  * Changed init to remember if initialized.
  34.  * 
  35.  * Revision 1.3  93/02/24  10:28:25  10:28:25  jraja (Jarno Tapio Rajahalme)
  36.  * Changed max_linkhdr to 0.
  37.  * 
  38.  * Revision 1.2  93/02/24  09:59:36  09:59:36  jraja (Jarno Tapio Rajahalme)
  39.  * Fixed timeout()'s, commented out unix and route domains.
  40.  * 
  41.  * Revision 1.1  92/11/19  12:06:47  12:06:47  jraja (Jarno Tapio Rajahalme)
  42.  * Initial revision
  43.  * 
  44.  *
  45.  */
  46.  
  47. /*
  48.  * Copyright (c) 1982, 1986 Regents of the University of California.
  49.  * All rights reserved.
  50.  *
  51.  * Redistribution and use in source and binary forms, with or without
  52.  * modification, are permitted provided that the following conditions
  53.  * are met:
  54.  * 1. Redistributions of source code must retain the above copyright
  55.  *    notice, this list of conditions and the following disclaimer.
  56.  * 2. Redistributions in binary form must reproduce the above copyright
  57.  *    notice, this list of conditions and the following disclaimer in the
  58.  *    documentation and/or other materials provided with the distribution.
  59.  * 3. All advertising materials mentioning features or use of this software
  60.  *    must display the following acknowledgement:
  61.  *    This product includes software developed by the University of
  62.  *    California, Berkeley and its contributors.
  63.  * 4. Neither the name of the University nor the names of its contributors
  64.  *    may be used to endorse or promote products derived from this software
  65.  *    without specific prior written permission.
  66.  *
  67.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  68.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  69.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  70.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  71.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  72.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  73.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  74.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  75.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  76.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  77.  * SUCH DAMAGE.
  78.  *
  79.  *    @(#)uipc_domain.c    7.9 (Berkeley) 3/4/91
  80.  */
  81.  
  82. #include <conf.h>
  83.  
  84. #include <sys/param.h>
  85. #include <sys/socket.h>
  86. #include <sys/protosw.h>
  87. #include <sys/domain.h>
  88. #include <sys/mbuf.h>
  89. #include <sys/kernel.h>
  90.  
  91. #include <kern/amiga_includes.h>
  92. #include <kern/uipc_domain_protos.h>
  93.  
  94. /* --- start moved from sys/domain.h --- */
  95. struct    domain *domains = NULL;
  96. /* --- end moved from sys/domain.h --- */
  97.  
  98. static BOOL domain_initialized = FALSE;
  99.  
  100. #define    ADDDOMAIN(x)    { \
  101.     extern struct domain __CONCAT(x,domain); \
  102.     __CONCAT(x,domain.dom_next) = domains; \
  103.     domains = &__CONCAT(x,domain); \
  104. }
  105.  
  106. BOOL
  107. domaininit()
  108. {
  109.     register struct domain *dp;
  110.     register struct protosw *pr;
  111.  
  112.     if (domain_initialized)
  113.       return TRUE;
  114.  
  115. #undef unix
  116. #ifndef AMITCP
  117.     ADDDOMAIN(unix);
  118. #endif /* AMITCP */
  119.     ADDDOMAIN(route);
  120. #if INET
  121.     ADDDOMAIN(inet);
  122. #endif
  123. #if NS
  124.     ADDDOMAIN(ns);
  125. #endif
  126. #if ISO
  127.     ADDDOMAIN(iso);
  128. #endif
  129. #if RMP
  130.     ADDDOMAIN(rmp);
  131. #endif
  132. #if CCITT
  133.     ADDDOMAIN(ccitt);
  134. #endif
  135. #if NIMP > 0
  136.     ADDDOMAIN(imp);
  137. #endif
  138.  
  139.     for (dp = domains; dp; dp = dp->dom_next) {
  140.         if (dp->dom_init)
  141.             (*dp->dom_init)();
  142.         for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
  143.             if (pr->pr_init)
  144.                 (*pr->pr_init)();
  145.     }
  146. #ifdef AMITCP
  147.   /*
  148.    * No space needed for the link header with SanaII drivers
  149.    */
  150.   max_linkhdr = 0;
  151. #else
  152. if (max_linkhdr < 16)        /* XXX */
  153. max_linkhdr = 16;
  154. #endif
  155.     max_hdr = max_linkhdr + max_protohdr;
  156.     max_datalen = MHLEN - max_hdr;
  157.  
  158. #ifndef AMITCP
  159.     /*
  160.      * Timeouts are scheduled from amiga_main.c in AmiTCP/IP
  161.      */
  162.     pffasttimo();
  163.     pfslowtimo();
  164. #endif
  165.     domain_initialized = TRUE;
  166.     return TRUE;
  167. }
  168.  
  169. struct protosw *
  170. pffindtype(family, type)
  171.     int family, type;
  172. {
  173.     register struct domain *dp;
  174.     register struct protosw *pr;
  175.  
  176.     for (dp = domains; dp; dp = dp->dom_next)
  177.         if (dp->dom_family == family)
  178.             goto found;
  179.     return (0);
  180. found:
  181.     for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
  182.         if (pr->pr_type && pr->pr_type == type)
  183.             return (pr);
  184.     return (0);
  185. }
  186.  
  187. struct protosw *
  188. pffindproto(family, protocol, type)
  189.     int family, protocol, type;
  190. {
  191.     register struct domain *dp;
  192.     register struct protosw *pr;
  193.     struct protosw *maybe = 0;
  194.  
  195.     if (family == 0)
  196.         return (0);
  197.     for (dp = domains; dp; dp = dp->dom_next)
  198.         if (dp->dom_family == family)
  199.             goto found;
  200.     return (0);
  201. found:
  202.     for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) {
  203.         if ((pr->pr_protocol == protocol) && (pr->pr_type == type))
  204.             return (pr);
  205.  
  206.         if (type == SOCK_RAW && pr->pr_type == SOCK_RAW &&
  207.             pr->pr_protocol == 0 && maybe == (struct protosw *)0)
  208.             maybe = pr;
  209.     }
  210.     return (maybe);
  211. }
  212.  
  213. void
  214. pfctlinput(cmd, sa)
  215.     int cmd;
  216.     struct sockaddr *sa;
  217. {
  218.     register struct domain *dp;
  219.     register struct protosw *pr;
  220.  
  221.     for (dp = domains; dp; dp = dp->dom_next)
  222.         for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
  223.             if (pr->pr_ctlinput)
  224.                 (*pr->pr_ctlinput)(cmd, sa, (caddr_t) 0);
  225. }
  226.  
  227. void
  228. pfslowtimo()
  229. {
  230.     register struct domain *dp;
  231.     register struct protosw *pr;
  232.  
  233.     for (dp = domains; dp; dp = dp->dom_next)
  234.         for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
  235.             if (pr->pr_slowtimo)
  236.                 (*pr->pr_slowtimo)();
  237. #ifndef AMITCP
  238.     /*
  239.      * Timeouts are scheduled from amiga_main.c in AmiTCP/IP
  240.      */
  241.     timeout(pfslowtimo, (caddr_t)0, hz/2);
  242. #endif /* AMITCP */       
  243. }
  244.  
  245. void
  246. pffasttimo()
  247. {
  248.     register struct domain *dp;
  249.     register struct protosw *pr;
  250.  
  251.     for (dp = domains; dp; dp = dp->dom_next)
  252.         for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
  253.             if (pr->pr_fasttimo)
  254.                 (*pr->pr_fasttimo)();
  255. #ifndef AMITCP
  256.     /*
  257.      * Timeouts are scheduled from amiga_main.c in AmiTCP/IP
  258.      */
  259.     timeout(pffasttimo, (caddr_t)0, hz/5);
  260. #endif /* AMITCP */       
  261. }
  262.